<template>
<div>
  <t-table rowKey="index" size="small" :data="data" :columns="columns" hover :pagination="pagination"
           :loading="dataLoading" :sort="sort" :hideSortTips="true" @sort-change="sortChange">
    <template #projectName="{ row }">
<!--      <t-link @click="dialog.objId=row.id;dialog.header=row.projectName;dialog.open_project_detail=true" hover="color" theme="primary">{{ row.projectName }}</t-link>-->
      {{ row.projectName }}
    </template>
    <template #adviceFunding="{ row }">
      {{ row.adviceFunding }}万元
    </template>
<!--    <template #projectStatus="{ row }">-->
<!--      <t-tag  @click="dialog.header=row.projectName;dialog.objId=row.id;dialog.open_approve_list=true" class="cursor-pointer" :theme="handleTheme(row.projectStatus, dict.type.sf_project_status)" variant="light">-->
<!--        {{ row.projectStatus | filterByDict(dict.type.sf_project_status) }}-->
<!--      </t-tag>-->
<!--    </template>-->
<!--    <template #op="{ row }">-->
<!--      <t-button size="small" @click="dialog.objId=row.id;dialog.header=row.projectName;dialog.open_project_detail=true" variant="text" class="t-button-link">-->
<!--        <t-icon name="info-circle" slot="icon"/>-->
<!--        详情-->
<!--      </t-button>-->
<!--    </template>-->
  </t-table>
  <project-detail-dialog  tabDefaultValue="1" :header="dialog.header" :objId="dialog.objId" :visible.sync="dialog.open_project_detail"
                          v-if="dialog.open_project_detail"></project-detail-dialog>
  <approve-list :header="dialog.header" :objId="dialog.objId" :visible.sync="dialog.open_approve_list"
                v-if="dialog.open_approve_list"></approve-list>
</div>
</template>

<script>
// import projectDetailDialog from "../../../kjsf/project/components/project-detail-dialog.vue";
import approveList from "../../../kjsf/approve/components/approve-list.vue";

export default {
  name: "kjsf-list",
  dicts:["sf_project_status"],
  components:{
    // projectDetailDialog,
    projectDetailDialog: () => import('../../../kjsf/project/components/project-detail-dialog.vue'),

    approveList
  },
  props:["deptId", "idCard"],
  data() {
    return {
      dialog: {
        open: false,
        header: "",
        row: {},
        data: {},
        open_project_detail: false,
        open_outline_detail: false,
        open_contract_detail: false,
        objId: 0,
        open_approve_list: false
      },
      nowRow:{},
      deleteVisible:false,
      queryParams:{
        pageNum:1,
        pageSize:10,
        projectName:"",
        projectNum: '',
        localStandardStatus: '',
        formulateType:"",
        publicDateRange:[],
        standardProperty: '',
        standardCategory: '',
        draftUnitNames: '',
        draftPersonNames: '',
        startPublishDate: '',
        endPublishDate: '',
        deptId: this.deptId,
        idCard: this.idCard,
      },
      deptMenuOptions:[],
      pagination: {
        current: 1,
        pageSize: 10,
        total: 0,
        showPageSize: true,
        pageSizeOptions: [10, 20, 30, 50],
        showFirstAndLastPageBtn: false,
        onChange: (pageInfo) => {
          Object.assign(this.pagination,pageInfo)
          this.queryParams.pageNum = pageInfo.current || 1;
          this.queryParams.pageSize = pageInfo.pageSize;
          this.getList()
        },
      },
      sort:[],
      dataLoading: false,
      columns:[
        {
          colKey: "projectName",
          title: "项目名称",
          align: "center",
          width: 220
        },
        {
          colKey: "declareDate",
          title: "申报日期",
          align: "center",
          width: 160,
        },
        {
          colKey: "startDate",
          title: "项目开始日期",
          align: "center",
          width: 160,
        },
        {
          colKey: "endDate",
          title: "项目结束日期",
          align: "center",
          width: 160,
        },
        {
          colKey: "manageDeptName",
          title: "主管单位名称",
          align: "center",
          width: 160,
        },
        {
          colKey: "adviceFunding",
          title: "拟投入经费",
          align: "center",
          width: 160,
        },
        {
          colKey: "keyWord",
          title: "关键词",
          align: "center",
          width: 160,
        },
        {
          colKey: "declareDeptName",
          title: "申报单位",
          align: "center",
          width: 160,
        },
        // {
        //   colKey: "projectStatus",
        //   title: "项目状态",
        //   align: "center",
        //   width: 160,
        // },
        // {
        //   colKey: "op",
        //   title: "操作",
        //   align: "center",
        //   width: 120,
        //   fixed: 'right'
        // },
      ],
      opinionVisible: true,
      data: [],

    }
  },
  async created() {
    await this.getDeptTreeSelect()
    this.getList()
  },
  methods:{
    getDeptTreeSelect() {
      return this.$api.system.dept.treeSelectAllIn().then(response => {
        this.deptMenuOptions = response.data;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    sortChange(sort){
      this.sort = sort;
      let orderByColumn = []
      let isAsc = []
      if(sort instanceof Array){
        orderByColumn = sort.map(val=>val.sortBy)
        isAsc = sort.map(val=>val.descending?`desc`:`asc`)
      }else {
        orderByColumn = [sort.sortBy]
        isAsc = [sort.descending?`desc`:`asc`]
      }
      this.queryParams.orderByColumn = orderByColumn.join(",")
      this.queryParams.isAsc = isAsc.join(",")
      this.getList();
    },
    getList(){
      // [this.queryParams.startPublishDate,this.queryParams.endPublishDate] = this.queryParams.publicDateRange;
      if(this.deptId){
        this.dataLoading = true
        this.$api.kjsf.project.list(this.queryParams).then(response=>{
          this.pagination.total = response.total
          this.data = response.rows
          this.dataLoading = false
        }).catch(e=>{
          this.dataLoading = false
          this.$message.error(e.toString())
        })
      }else if(this.idCard){
        this.dataLoading = true
        this.$api.kjsf.project.myJoinList(this.queryParams).then(response=>{
          this.pagination.total = response.total;
          this.data = response.rows;
          this.dataLoading = false;
        }).catch((e) => {
          this.dataLoading = false;
          this.$message.error(e.toString());
        });
      }

    }
  }
}
</script>

<style scoped>

</style>
